package com.malinkang.sqlite;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;

import org.greenrobot.greendao.identityscope.IdentityScopeType;


public class DBManager {
    public static final String DB_NAME = "student.db";
    DaoSession mDaoSession;

    public DaoSession getDaoSession() {
        return mDaoSession;
    }

    private DBManager(Context context) {
        DaoMaster.DevOpenHelper devOpenHelper = new DaoMaster.DevOpenHelper(context, DB_NAME);
        SQLiteDatabase db = devOpenHelper.getWritableDatabase();
        mDaoSession = new DaoMaster(db).newSession(IdentityScopeType.None);
    }

    private static DBManager instance;

    public static DBManager getInstance(Context context) {
        if (instance == null) {
            instance = new DBManager(context);
        }
        return instance;
    }

    public static StudentDao getStudentDao(Context context) {
        return getInstance(context).getDaoSession().getStudentDao();
    }


    public static OrderDao getOrderDao(Context context) {
        return getInstance(context).getDaoSession().getOrderDao();
    }

    public static CustomerDao getCustomerDao(Context context) {
        return getInstance(context).getDaoSession().getCustomerDao();
    }


}
